function [ dsignal, t ] = ManchesterSignal( data )
%MANCHESTERSIGNAL Constructs a signal with manchester encoding
%   Expects the data in Least Significant Byte and Bit first order
%   Start and end sequence will be added by this
%   function
%   Returns the signal and a debug variable for sampling

% constants
f=848e3; % carrier frequency

% add start sequence
data = [1 data];

% data size
dlength = size(data,2) + 1; % + 1 for end sequence

% create clock
spacing = 200; % Spacing is needed for straight edges
dsignal = zeros(1,spacing*dlength ); 

% data signal 
for i=1:1:(dlength-1) % don't modulate end-sequence
    dsignal((i-1)*spacing+1:(i-1)*spacing+(spacing/2))=data(i);
    dsignal((i-1)*spacing+(spacing/2 + 1):i*spacing)=1 - data(i);
end

% create plot scale
t = linspace(0, dlength/f, spacing*dlength);
end

